package com.company4.students;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class mainlist {
    public static void getStart() throws AgeException, IdException {
        // 定义学生集合
        List<student> listStudents = null;

        // 指向学生集合文件
        File txt = new File("D:\\Homwork\\listStudents.txt");
        if (txt.exists()) {
            // 如果文件存在则读取
            listStudents = ReadList.readList();
        }else{
            // 如果不存在则创建一个新集合
            listStudents = new LinkedList<>();
        }

        Scanner sc = new Scanner(System.in);
        int flag;

        outer:while (true) {
            Menu.getMenu();
            flag = sc.nextInt();
            switch (flag) {
                case 1:
                    // 添加学生
                    addstudent.addStudent(sc, listStudents);
                    break;
                case 2:
                    // 查找学生并打印
                    printstudent.printStudents((List<student>) serchstudent.seachStudent(sc, listStudents));
                    break;
                case 3:
                    // 删除学生
                    delstudent.deleteStudent(sc, listStudents);
                    break;
                case 4:
                    // 修改学生信息
                    changestudent.changeStudent(sc, serchstudent.seachStudent(sc, listStudents));
                    break;
                case 5:
                    // 打印所有学生
                    printstudent.printStudents(listStudents);
                    break;
                case 0:
                    // 退出系统
                    System.out.println("正在退出系统...");
                    // 将集合写入文件
                    WriteList.writeList(listStudents);
                    break outer;
                default:
                    System.out.println("请重新选择");
                    break;
            }
        }
        sc.close();

    }
}
